import React, {useReducer} from 'react'
// 引入store中的state和reducer
import { initState, reducer } from '../store'

export default function ReudcerFn() {
  // useReducer的作用是，在函数组件中使用reducer相关的功能
  const [state, dispatch] = useReducer(reducer,initState)
  const changeAge = ()=>{
    dispatch({type: 'AGEADD'})
  }
  return (
    <div>
      <p>useReducer的使用</p>
      <p>{state.age}</p>
      <p>{state.name}</p>
      <button onClick={()=>changeAge()}>年龄+1</button>
    </div>
  )
}
